package com.example.workflow.controller;

import com.example.workflow.dto.ProcessDeployRequest;
import com.example.workflow.dto.SystemRequest;
import com.example.workflow.service.SystemService;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.example.workflow.entity.SysSystem;
import com.example.workflow.entity.SysProcess;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import com.example.workflow.common.Result;
@RestController
@RequestMapping("/system")
public class SystemController {

    @Autowired
    private SystemService systemService;

    @PostMapping("/save")
    public void saveSystem(@RequestBody SystemRequest request) {
        systemService.saveSystem(request);
    }

    @GetMapping("/list")
    public Result<List<SysSystem>> getSystemList() {
        return Result.success(systemService.getSystemList());
    }

    @PostMapping("/process/deploy")
    public void deployProcess(@ModelAttribute ProcessDeployRequest request) throws IOException {
        systemService.deployProcess(request);
    }

    @GetMapping("/process/{processKey}/instances")
    public Result<List<ProcessInstance>> getRunningProcesses(@PathVariable String processKey) {
        return Result.success(systemService.getRunningProcesses(processKey));
    }

    @DeleteMapping("/{systemId}")
    public void deleteSystem(@PathVariable Long systemId) {
        systemService.deleteSystem(systemId);
    }
} 